package com.mdnote.practice.linked_list;

import org.junit.Test;

import java.util.List;

/**
 * @author Rhythm-2019
 * @version 1.0
 * @date 2020/11/13 11:36
 * @Email rhythm_2019@163.com
 * @Description
 */
public class LeetCode328 {

    public ListNode oddEvenList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        // drute solution
        ListNode oddNode = head, evenNode = head.next;
        ListNode tmpNode = head.next;
        while (evenNode != null && evenNode.next != null) {
            oddNode.next = evenNode.next;
            oddNode = evenNode.next;
            evenNode.next = oddNode.next;
            evenNode = oddNode.next;;
        }

        oddNode.next = tmpNode;
        return head;
    }

      public static class ListNode {
          int val;
          ListNode next;
          ListNode() {}
          ListNode(int val) { this.val = val; }
          ListNode(int val, ListNode next) { this.val = val; this.next = next; }
      }

      @Test
    public void test_01() {
          LeetCode328 leetCode328 = new LeetCode328();
          ListNode head = new ListNode(1);
          head.next = new ListNode(2);
          head.next.next = new ListNode(3);
          head.next.next.next = new ListNode(4);
          head.next.next.next.next = new ListNode(5);
          head.next.next.next.next.next = new ListNode(6);
          leetCode328.oddEvenList(head);
      }
}
